package sort;

import java.util.Arrays;

/**
 * @Author Zhouchb
 * @Create 2021-10-2021/10/26 :13:16
 * @Description
 */
public class Bubble {
    public static void main(String[] args) {
        Integer[] i ={3,9,1,8,5,4,7};
        bubbleSore(i);

    }
    public static void bubbleSore(Comparable[] arr){
        for (int i=arr.length-1;i>0;i--){
            for (int j = 0;j<i;j++){
                if (compare(arr[j],arr[j+1])){
                    swap(arr,j,j+1);
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }
    public static boolean compare(Comparable a,Comparable b){
            return a.compareTo(b)>0;
    }
    public static void swap(Comparable[] arr,int i,int j){
        Comparable c;
        c = arr[i];
        arr[i]=arr[j];
        arr[j]=c;
    }
}

